package edu.zjut.sjq.controller;

import edu.zjut.sjq.bean.Like;
import edu.zjut.sjq.service.LikeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by sue on 2017/3/18.
 */
@Controller
@RequestMapping("/like")
public class LikeController {
    @Autowired
    private LikeService likeService;

    /**
     * 点赞或者取消赞
     * @return
     */
    @RequestMapping(value = "/addOrRemove",produces="application/json")
    @ResponseBody
    public Integer addOrRemove(@RequestBody Like like){
        return likeService.addOrRemove(like.getArticleId());
    }

    /**
     * 获取该作品的赞数量
     * @param articleId
     * @return
     */
    @RequestMapping("/getTotalNum")
    @ResponseBody
    public Integer getTotalLikeNum(@RequestParam("articleId") Integer articleId){
        return likeService.getTotalLikeNum(articleId);
    }

}
